
// import desingerCreater from "@/desinger/index"

// const bodyContainer = document.getElementById("container");
// import pageConfig from "./pageConfig";

// import { renderViewBud } from "@ViewBud/index";


// // desingerCreater(bodyContainer);
// renderViewBud(pageConfig).appendTo("#body-container");

class LinkedNode {
    next: LinkedNode | null = null;
    current: () => void
    constructor(current: () => void) {
        this.current = current;
    }

}

class ExecLinked {
    header: LinkedNode | null = null;
    tail: LinkedNode | null = null;
    constructor() { }
    push() { }
    remove() { }
    exec() { }
}
function createExecQueue() {

}
let ActiveEffect: ReactiveEffect | null = null;
const effectMap = new Map<State, Array<ReactiveEffect>>();
class State {
    private _state: any = null;
    constructor(initValue: any) {
        this._state = initValue;
    }
    get value() {
        if (ActiveEffect) {
            let currentEffects = effectMap.get(this) || [];
            currentEffects.indexOf(ActiveEffect) < 0 && currentEffects.push(ActiveEffect);
            effectMap.set(this, currentEffects);
        }
        return this._state;
    }
    set value(val: any) {
        this._state = val;

        if (effectMap.has(this)) {
            effectMap.get(this)?.forEach((fn) => {
                fn.run();
            });
        }
        // this._state = val;
    }
}
function ref(value: any) {
    return new State(value);
}

class ReactiveEffect {
    private fn: () => void;
    constructor(fn: () => void) {
        this.fn = fn;
    }
    run() {
        ActiveEffect = this;
        this.fn();
        ActiveEffect = null;
    }
    stop() {
        //将自己从状态的依赖列表里删除
        effectMap.forEach((effect, state, arr) => {
            let index = effect.indexOf(this);

            if (index >= 0) {
                const currentEffects = effectMap.get(state);
                currentEffects && currentEffects.splice(index, 1);
                effectMap.set(state, currentEffects || [])
            }
        })
    }
}

function effect(fn: () => void) {
    const effectTarget = new ReactiveEffect(fn);
    effectTarget.run();
    return effectTarget;
}


const title = ref("大年初一！规划内容！！！");
const effectTarget = effect(() => {
    console.log("title", title.value);
})
title.value = "大年初二！一定要写完！！！";
effectTarget.stop();
title.value = "大年初三去看狙击手！！！";
